#include <stdio.h>
#include "send.h"
#include "modul.h"

/*
 * 函数名:send_M0
 * 功能:向M0发送数据
 * 参数:dev *dev:设备控制结构体
 * 返回值:成功返回OK,失败返回ERR
 */

int send_M0(server_to_client data)
{
	unsigned char *p = NULL;
	int ret = data.rfid_card[4];
	if(ret == 0){
		if('0' == data.dev.air_fan){
			p = "FAN_OFF";
		}
		else if('1' == data.dev.air_fan){
			p = "FAN_ON";
		}
		else if('0' == data.dev.sunshade){
			p = "LIGHT_OFF";		
		}
		else if('1' == data.dev.sunshade){
			p = "LIGHT_ON";
		}
		else if('0' == data.dev.spray_water){
			p = "SHU_OFF";
		}
		else if('1' == data.dev.spray_water){
			p = "SHU_ON";
		}
		ret = zigbee_exe_cmd(zgbfd,p);
	}
	else
	{
		if(data.rfid_card[0] == 0xCC && 1 == data.rfid_card[7]  && 0 == data.rfid_card[6] && 33 == data.rfid_card[5] && 18 == data.rfid_card[4])
		{
			//printf("111111\n");
			p = "SHU_OFF";
			//memset(data.rfid_card,0,RFID_CARD_NUM_SIZE);
		}
		else{
			p = "SHU_ON";
		}
		zigbee_exe_cmd(zgbfd, p);
	}

	if(0 < ret)
	{
		return ERR;
	}
	return OK;
}